package org.come.view;

import com.tool.ModerateTask.Hero;
import com.tool.ModerateTask.Task;
import com.tool.btn.TaskGuideBtn;
import com.tool.tcpimg.InputBean;
import com.tool.tcpimg.RichLabel;
import com.updateNew.MyIsif;

import org.come.mouslisten.Mouselistener;
import org.come.until.CutButtonImage;

import javax.swing.*;
import javax.swing.event.MouseInputListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.List;



public class TaskGuideView extends JComponent implements MouseInputListener{
//首页任务栏
	private boolean isV;
	private boolean isTypeOne;
	private boolean isTypeTwo;
	private TaskGuideBtn guideBtn1,guideBtn2;
	private int H;
	private InputBean inputBean;
	public TaskGuideView() {
		// TODO Auto-generated constructor stub
		H=121;
		this.setBounds(0, 150, 188, H);
		this.addMouseListener(this);
	    this.addMouseMotionListener(this);
		this.setVisible(false);
	    this.isV=false;
		this.isTypeOne=false;
		this.isTypeTwo=false;
		if("水墨UI".equals(MyIsif.getStyle())) {
			guideBtn1=new TaskGuideBtn("inkImg/old/1/12.png", 1, 0, this);
			guideBtn1.setBounds(5, 2, 20, 20);
			this.add(guideBtn1);
			guideBtn2=new TaskGuideBtn("skin/8100226/newbutton/syrw.png", 1, 1, this);//任务追踪
			guideBtn2.setBounds(0, 0, 188, 23);
			guideBtn2.addMouseMotionListener(this);//任务栏点击自动寻路代码
			this.add(guideBtn2);
		}else{
			guideBtn1=new TaskGuideBtn("inkImg/hongmu/2/26_png.button.btn_left.png", 1, 0, this);
			guideBtn1.setBounds(5, 2, 20, 20);
			this.add(guideBtn1);
			guideBtn2=new TaskGuideBtn("skin/8100226/newbutton/syrwh.png", 1, 1, this);//任务追踪
			guideBtn2.setBounds(0, 0, 188, 23);
			guideBtn2.addMouseMotionListener(this);//任务栏点击自动寻路代码
			this.add(guideBtn2);
		}

	}
	ImageIcon icon_sm=new ImageIcon("skin/8100226/newbutton/B75.png");//任务追踪背景

	ImageIcon icon_hm=new ImageIcon("skin/8100226/newbutton/B75h.png");//任务追踪背景


	@Override
	protected void paintComponent(Graphics g) {
		if (isTypeOne||isTypeTwo) {
			return;
		}else {

			if("水墨UI".equals(MyIsif.getStyle())) {
				g.drawImage(icon_sm.getImage(), 0, 23, 188, getHeight()-23, null);
			}else{
				g.drawImage(icon_hm.getImage(), 0, 23, 188, getHeight()-23, null);
			}




			List<Task> tasks=Hero.getList();
			if (tasks!=null&&tasks.size()!=0) {
				int History=0;
				int hig=23;
				g.translate(5,23);
				for (int i = 0; i < tasks.size(); i++) {
					RichLabel richLabel=tasks.get(i).getRichLabel();
					if (richLabel!=null) {
						g.translate(0, History);
						History = richLabel.getHeight();
						hig+=History;
						richLabel.paint(g);
					}
				}
				g.translate(-5, -hig+History);
				hig+=5;
				if (hig!=H) {
					H=hig;
					this.setBounds(getX(), getY(), getWidth(), H);
				}
			}else if (H!=121) {
				H=121;
				this.setBounds(getX(), getY(), getWidth(), H);
			}
		}
	}
	/**刷新引导*/
	public void guideSX(List<Task> tasks){
		if (isV!=(tasks!=null&&tasks.size()!=0)) {
			isV=!isV;
			this.setVisible(isV);
		}
	}
	public void guideShow(int type){
		try {
			if (type==0) {
				isTypeOne=!isTypeOne;
				if("水墨UI".equals(MyIsif.getStyle())) {
					if (isTypeOne) {
						guideBtn1.setIcons(CutButtonImage.cuts("inkImg/old/1/11.png"));
						guideBtn1.setBounds(5, 1, 20, 20);
						this.setBounds(0, 150, 20, 20);
					}else {
						guideBtn1.setIcons(CutButtonImage.cuts("inkImg/old/1/12.png"));
						guideBtn1.setBounds(5, 2, 20, 20);
						this.setBounds(0, 150, 188, H);
					}
				}else{
					if (isTypeOne) {
						guideBtn1.setIcons(CutButtonImage.cuts("inkImg/hongmu/1/ss565.png"));
						guideBtn1.setBounds(1, 1, 19, 19);
						this.setBounds(0, 150, 20, 20);
					}else {
						guideBtn1.setIcons(CutButtonImage.cuts("inkImg/hongmu/2/26_png.button.btn_left.png"));
						guideBtn1.setBounds(5, 2, 20, 20);
						this.setBounds(0, 150, 188, H);
					}
				}

			}else if (type==1){
				isTypeOne=!isTypeOne;
				if (isTypeOne) {
					this.setBounds(getX(), getY(), 188, 23);
				}else {
					this.setBounds(getX(), getY(), 188, H);
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	private int first_x,first_y;//x、y坐标
	public void DJ(int x,int y){
		this.first_x=x;
		this.first_y=y;
	}
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}
	@Override
	public void mousePressed(MouseEvent e) {
		this.first_x = e.getX();
		this.first_y = e.getY();
		List<Task> tasks=Hero.getList();
		if (tasks!=null&&tasks.size()!=0) {
			int hig=23;
			for (int i = 0; i < tasks.size(); i++) {
				RichLabel richLabel=tasks.get(i).getRichLabel();
				if (richLabel!=null) {
					InputBean bean=richLabel.isMonitor(first_x-5, first_y-hig);
					if (bean!=null) {
						inputBean=bean;
						inputBean.setM(true);
						return;
					}
					hig+=richLabel.getHeight();
				}
			}
		}
	}
	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		if (inputBean!=null) {
			Mouselistener.DJInputBean(inputBean);
			inputBean=null;
		}
	}
	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}
	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}
	@Override
	public void mouseDragged(MouseEvent e) {
		int x = e.getX() - first_x;
		int y = e.getY() - first_y;
		setBounds(x + getX(), y + getY(),getWidth(),getHeight());
	}
	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub

	}
	public boolean isV() {
		return isV;
	}
}
